<template>
  <div class="login-wrap">
    <div class="ms-login">
      <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
        <el-form-item prop="account" class="m-top">
          <el-input v-model="param.account" placeholder="account" class="intput" style="height: 50px;">
            <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
              type="password"
              placeholder="password"
              v-model="param.password"
              @keyup.enter.native="submitForm()"
              class="intput"
              size="medium"
              style="height: 50px;"
          >
            <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
          </el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
    import { loginIn } from '../../api/login';
export default {
    data: function() {
        return {
            param: {
                account: '',
                password: '',
            },
            rules: {
                account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    methods: {
        submitForm() {
            var _that =this;
            this.$refs.login.validate(valid => {
                if (valid) {
                    loginIn(_that.param).then(response => {
                        const { data } = response
                        this.$message.success('登录成功');
                        localStorage.setItem("X-Token", response.token);
                        localStorage.setItem('ms_username',  response.user.account);
                        localStorage.setItem('ms_userid',  response.user.id);
                        localStorage.setItem('ms_userrole',  response.user.roleId);
                        localStorage.setItem('ms_userrolenames',  response.user.rolenames);
                        this.$router.push('/');
                    }).catch(error => {
                        this.$message.success('登录失败');
                    })
                } else {
                    this.$message.error('请输入账号和密码');
                    console.log('登录失败');
                    return false;
                }
            });
        },
    },
};
</script>

<style scoped>
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url(../../assets/img/bgImg.jpg);
  background-size: 100%;
}
.ms-login {
  position: absolute;
  left: 50%;
  width: 500px;
  border-radius: 5px;
  margin-top: 25%;
  margin-left: 15%;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}
.ms-content {

  padding: 30px 30px;
}
.login-btn {
  text-align: center;
}
.login-btn button {
  width: 100%;
  height: 50px;
  margin-bottom: 10px;
}
.m-top{
  margin-top: 10px;
}

.intput{
  height: 50px;
}

>>> .el-input__inner{
  height: 50px;
}

</style>